<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<title>Class: VBulletinRails::User</title>

<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
</script>

<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="../index.html">Home</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>lib/vbulletin_rails/models/user.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link"><a href="../ActiveRecord/Base.html">ActiveRecord::Base</a>
  
</nav>

    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-c-register">::register</a>
    
    <li><a href="#method-i-authenticate">#authenticate</a>
    
    <li><a href="#method-i-authenticate_bb_password">#authenticate_bb_password</a>
    
    <li><a href="#method-i-bb_password">#bb_password</a>
    
    <li><a href="#method-i-defaults">#defaults</a>
    
    <li><a href="#method-i-password-3D">#password=</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="../LICENSE.html">LICENSE</a>
  
    <li class="file"><a href="../TODO.html">TODO</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="../Rails/Application/Configuration.html">Rails::Application::Configuration</a>
  
    <li><a href="../VBulletinRails.html">VBulletinRails</a>
  
    <li><a href="../VBulletinRails/Session.html">VBulletinRails::Session</a>
  
    <li><a href="../VBulletinRails/User.html">VBulletinRails::User</a>
  
    <li><a href="../ActionController/Base.html">ActionController::Base</a>
  
    <li><a href="../ActiveRecord/Base.html">ActiveRecord::Base</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class VBulletinRails::User</h1>

  <div id="description" class="description">
    
<p>Model containing VBulletin <a href="User.html">User</a> information</p>

  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    
    <!-- Constants -->
    <section id="constants-list" class="section">
      <h3 class="section-header">Constants</h3>
      <dl>
      
        <dt id="PREFIX">PREFIX
        
        <dd class="description"><p>VBulletin tables prefix in database. It must set same as
<code>$config['Database']['tableprefix']</code> in your VBulletin forum</p>
        
      
      </dl>
    </section>
    

    

    <!-- Methods -->
    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Class Methods</h3>

    
      <div id="method-c-register" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">register</span><span
            class="method-args">(options)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Registers VBulletin user with given username/email and password</p>

<pre class="ruby"><span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">User</span>.<span class="ruby-identifier">register</span> :<span class="ruby-identifier">username</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'username'</span>,      :<span class="ruby-identifier">password</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'user password'</span>
<span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">User</span>.<span class="ruby-identifier">register</span> :<span class="ruby-identifier">email</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'user@example.com'</span>, :<span class="ruby-identifier">password</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'user password'</span>
</pre>
          

          
          <div class="method-source-code" id="register-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/models/user.rb, line 77</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">register</span> <span class="ruby-identifier">options</span>
  <span class="ruby-identifier">vb_user</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">vb_user</span>.<span class="ruby-identifier">save</span>
    <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">execute</span>(<span class="ruby-node">&quot;UPDATE `#{PREFIX}user` SET `birthday_search` = '0000-00-00' WHERE `#{PREFIX}user`.`userid` = '#{vb_user.userid}'&quot;</span>)
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">vb_user</span>.<span class="ruby-identifier">userid</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">vb_user</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- register-source -->
          
        </div>

        

        
      </div><!-- register-method -->

    
    </section><!-- public-class-method-details -->
  
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-authenticate" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">authenticate</span><span
            class="method-args">(passwd)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Authenticate VBulletin user with provided password. Returns <a
href="User.html">VBulletinRails::User</a> object if success</p>
          

          
          <div class="method-source-code" id="authenticate-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/models/user.rb, line 50</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">authenticate</span>(<span class="ruby-identifier">passwd</span>)
  <span class="ruby-constant">User</span>.<span class="ruby-identifier">password_hash</span>(<span class="ruby-identifier">passwd</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">salt</span>) <span class="ruby-operator">==</span> <span class="ruby-identifier">password</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- authenticate-source -->
          
        </div>

        

        
      </div><!-- authenticate-method -->

    
      <div id="method-i-authenticate_bb_password" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">authenticate_bb_password</span><span
            class="method-args">(bb_password_hash)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Authenticate VBulletin user with provided session hash. Returns <a
href="User.html">VBulletinRails::User</a> object if success</p>
          

          
          <div class="method-source-code" id="authenticate_bb_password-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/models/user.rb, line 55</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">authenticate_bb_password</span>(<span class="ruby-identifier">bb_password_hash</span>)
  <span class="ruby-identifier">bb_password_hash</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">bb_password</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">self</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- authenticate_bb_password-source -->
          
        </div>

        

        
      </div><!-- authenticate_bb_password-method -->

    
      <div id="method-i-bb_password" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">bb_password</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Returns correct VBulletin session hash for user</p>
          

          
          <div class="method-source-code" id="bb_password-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/models/user.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">bb_password</span>
  <span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">MD5</span>.<span class="ruby-identifier">hexdigest</span>(<span class="ruby-identifier">password</span> <span class="ruby-operator">+</span> <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">configuration</span>.<span class="ruby-identifier">vbulletin</span>.<span class="ruby-identifier">cookie_salt</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- bb_password-source -->
          
        </div>

        

        
      </div><!-- bb_password-method -->

    
      <div id="method-i-defaults" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">defaults</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Sets all unnecessary parameters as default for newly registered VBulletin
user.</p>
          

          
          <div class="method-source-code" id="defaults-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/models/user.rb, line 30</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">defaults</span>
  <span class="ruby-identifier">nowstamp</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">to_i</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">usergroupid</span> <span class="ruby-operator">||=</span> <span class="ruby-value">2</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">username</span> <span class="ruby-operator">||=</span> (<span class="ruby-keyword">self</span>.<span class="ruby-identifier">username</span>.<span class="ruby-identifier">blank?</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">email</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">username</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">usertitle</span> <span class="ruby-operator">||=</span> <span class="ruby-string">'Junior Member'</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">joindate</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">nowstamp</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">daysprune</span> <span class="ruby-operator">||=</span> <span class="ruby-value">-1</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">lastvisit</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">nowstamp</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">lastactivity</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">nowstamp</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">reputationlevelid</span> <span class="ruby-operator">||=</span> <span class="ruby-value">5</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">timezoneoffset</span> <span class="ruby-operator">||=</span> <span class="ruby-string">'0'</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">options</span> <span class="ruby-operator">||=</span> <span class="ruby-value">45108311</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">birthday_search</span> <span class="ruby-operator">||=</span> <span class="ruby-string">'1800-01-01'</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">startofweek</span> <span class="ruby-operator">||=</span> <span class="ruby-value">-1</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">languageid</span> <span class="ruby-operator">||=</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">userfield</span> = <span class="ruby-constant">Userfield</span>.<span class="ruby-identifier">new</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">usertextfield</span> = <span class="ruby-constant">Usertextfield</span>.<span class="ruby-identifier">new</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- defaults-source -->
          
        </div>

        

        
      </div><!-- defaults-method -->

    
      <div id="method-i-password-3D" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">password=</span><span
            class="method-args">(passwd)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Sets new <a href="User.html">VBulletinRails::User</a> password</p>
          

          
          <div class="method-source-code" id="password-3D-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/models/user.rb, line 65</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">password=</span> <span class="ruby-identifier">passwd</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">passwd</span>
  <span class="ruby-identifier">new_salt</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">fresh_salt</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">passworddate</span> = <span class="ruby-constant">Date</span>.<span class="ruby-identifier">today</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">salt</span> = <span class="ruby-identifier">new_salt</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:write_attribute</span>, <span class="ruby-value">:password</span>, <span class="ruby-constant">User</span>.<span class="ruby-identifier">password_hash</span>(<span class="ruby-identifier">passwd</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">new_salt</span>))
<span class="ruby-keyword">end</span></pre>
          </div><!-- password-3D-source -->
          
        </div>

        

        
      </div><!-- password-3D-method -->

    
    </section><!-- public-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

